﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 限制输入格式
/// </summary>
public class InputLimit : MonoBehaviour {
    InputField input;
	// Use this for initialization
	void Start () {
        input = GetComponent<InputField>();
        input.characterLimit = 1;//限制一个字符
        input.characterValidation = InputField.CharacterValidation.Integer;//限制整数
        input.onValueChanged.AddListener(delegate { NoNegative(); });//只保留正整数
    }

    void NoNegative()
    {
        if (input.text == "-")
        {
            input.text = "";
        }
    }
}
